package com.mark.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;

public class DBUtil {

    
    private static String driver = "com.mysql.jdbc.Driver";
    private static String url = "jdbc:mysql://10.4.14.186:3306/df35c4eb4109f4a398f12172c7982a880";
    private static String username = "uU7OuVA7qBBv2";
    private static String password = "pOtYr2GayWAU2";
    
    /*
    private static String driver = "com.mysql.jdbc.Driver";
    private static String url = "jdbc:mysql://localhost:3306/music_test";
    private static String username = "root";
    private static String password = "root";
    */
    private static Connection conn ;

    private DBUtil() {
    }

    public static Connection getConnection() {
    	try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            throw new ExceptionInInitializerError(e);
        } catch (SQLException e) {
            throw new ExceptionInInitializerError(e);
        }
        return conn;
    }

    public static void closeAll(Connection conn, Statement st, ResultSet rs) {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
        	throw new RuntimeException(e);
		} finally {
            try {
                if (st != null)
                    st.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            } finally {
                try {
                    if (rs != null)
                        rs.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

}